<?php 

namespace app\model;
use think\Model;

class Users extends Model {


	protected $connection = 'mysql';

 	protected $pk = 'id';

 	protected $name = 'users';

	function roles(){
		return $this->hasOne(\app\model\UsersRoles::class,'id','role_id');
	}

	public static function getusername($uid)
    {
        $user = self::find($uid);
        return $user->username;
    }


	public static function getallarray()
	{
		$list =	self::field('id,username')
			->order('id asc')
			->select()
			->toArray();
		$array = [];
		foreach ($list as $k => $v) {
			$array[$k]['val'] = $v['id'];
			$array[$k]['key'] = $v['username'];
		}
		return $array;
	}

}

